package tr3dtris.game;

import javax.swing.event.EventListenerList;
import tr3dtris.game.listeners.GameActionsListener;

/**
 * Class used to implement all the game logic connected to the user input.
 * Usually this class is managed by a keyboard <Controller> that maps
 * user input on keyboard and calls the correct method.
 * @author Luciano Mammino <loige@hotmail.com>
 * @author Andrea Mangano <kapitan0@hotmail.it>
 * @version 0.1
 * @since 0.1
 */
public class GameActions implements IGameActions
{

    


    /**
     * Reference to the connected <Game> class instance
     */
    protected Game game;

    /**
     * Constructor. Creates a new <GameActions>
     * @param game the connected <Game> instance
     */
    public GameActions(Game game)
    {
        this.game = game;
    }


    /**
     * {@inheritDoc}
     */
    public void start()
    {
        if(!this.game.isPlaying() && !this.game.isGameOver())
        {
            this.game.getGameLogic().start();
        }
    }

    /**
     * {@inheritDoc}
     */
    public void pause()
    {
        this.game.getGameLogic().pause();
    }

    /**
     * {@inheritDoc}
     */
    public void restart()
    {
        this.game.getGameLogic().restart();
    }

    /**
     * {@inheritDoc}
     */
    public void moveCurrentPieceDown()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().moveDown();
                this.game.refreshAllDisplay();
            }
    }

    /**
     * {@inheritDoc}
     */
    public void moveCurrentPieceLeft()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().moveLeft();
                this.game.refreshAllDisplay();
            }
    }

    /**
     * {@inheritDoc}
     */
    public void moveCurrentPieceRight()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().moveRight();
                this.game.refreshAllDisplay();
            }
    }

    /**
     * {@inheritDoc}
     */
    public void moveCurrentPieceUp()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().moveUp();
                this.game.refreshAllDisplay();
            }
    }

    /**
     * {@inheritDoc}
     */
    public void cwRotateCurrentPiece()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().rotateCw();
                this.game.refreshAllDisplay();
            }
    }

    /**
     * {@inheritDoc}
     */
    public void ccwRotateCurrentPiece()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().rotateCcw();
                this.game.refreshAllDisplay();
            }
    }

    /**
     * {@inheritDoc}
     */
    public void dropCurrentPiece()
    {
        if(this.game.isPlaying())
            if(this.game.getCurrentPiece() != null)
            {
                this.game.getCurrentPiece().drop();
                this.game.refreshAllDisplay();
            }
    }

    public void fireGameOver()
    {

    }



}